library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;


entity ROM is
generic (	N_DATA	: natural := 32;
		N_ROWS	: natural := 48;
		N_COLS	: natural := 8 );
port( 	address		: in   STD_LOGIC_VECTOR (N_DATA-1 downto 0);
		Instruction	: out STD_LOGIC_VECTOR (N_DATA-1 downto 0)
);
end ROM;

architecture Behav32 of ROM is
type Rom_Array is array (0 to N_ROWS-1) of std_logic_vector(N_COLS-1 downto 0);
signal content : Rom_Array;

begin

FILL_IN_MEM: process (address)
	variable index : integer := 0;
	begin		
		Content <= (	"10001100","00000001","00000000","00100000",
					"10001100","00010100","00000000","10001101",
					"00110000","00110100","00101000","00000010",
					"01000000","00000001","00000000","00000101",
					"01001100","00000000","00000000","00000110",
					"01101011","11100000","00000000","00000100",
					"00110100","00001000","00000000","00000101",
					"00011001","00011000","00000000","00000111",
					"00010010","10011101","00000000","01111001",
					"01010011","10100000","00000000","00000101",
					"00110011","00000000","11110001","10001100",
					"00100011","11001011","00000000","00000011"
			);
	
		index := to_integer(unsigned(address));
		Instruction <= content(index) & content(index+1) & content(index+2) & content(index+3);

	end process;

end Behav32;
--PC=0
		-- move 				"100011" 
		-- (Rs unused			"00000")
		-- in R[1] (value: 0)		"00001"
		-- the immediate 32	"0000000000100000"
		
--PC=4
		-- move				"100011"
		-- (Rs unused			"00000")
		-- in R[20] (value: 0)	"10100"
		-- the immediate 141	"0000000010001101" 
		
--PC=8
		-- perform ALU OP		"001100" 
		-- Rs: R[1] = 32		"00001"
		-- Rt: R[20] = 141		"10100"
		-- Rd: R[5]			"00101"
		--(shift unused		"00000")
		-- sum operation		"000010"
		
--PC=12
		-- store				"010000"
		--(Rs unsued			"00000")
		-- Rt[1] (value: 32)		"00001"
		-- in MEM[5] (value: 0)	"0000000000000101"
		
--PC=16
		-- jump to				"010011"
		--(Rs unsued				"00000")
		--(Rt unsued				"00000")
		-- 24 (imm: 6 (6*4=24))		"0000000000000110"
		
--PC=20
		-- this operation is not executed due to the previous jump
		-- but is jumped onto by the instruction @ PC=36
		-- jump if reg > 0						"011010"
		-- R[31] (value: 36)						"11111"
		-- (Rt unused							"00000")
		-- 40 (imm: 4 (4*4=16+npc=40)[npc=24])	"0000000000000100"
		
--PC=24
		-- load				"001101"
		--(Rs unsued		"00000")
		-- in R[8] (value: 0)		"01000"
		-- MEM[5] (value: 32)	"0000000000000101"
		
--PC=28
		-- multiply			"000110"
		-- to R[8] (value: 32)	"01000"
		-- in R[24] (value: 0)	"11000"
		-- the immediate 7		"0000000000000111"
		
--PC=32
		-- sub				"000100"
		-- to R[20] (value: 141)	"10100"
		-- in R[29] (value: 0)	"11101"
		-- the immediate 121	"0000000001111001" 
		
--PC=36
		-- jump and link Imm		"010100"
		-- NPC := R[29] (value: 20)	"11101"
		-- (Rt unused				"00000")
		-- 5 (5*4=20)				"0000000000000101"

--PC=40
		-- perform ALU OP		"001100" 
		-- Rs: R[24]= 224		"11000"
		-- (Rt unused			"00000")
		-- Rd: R[30] (value: 0)	"11110"
		--	shift 6 positions	"00110"
		-- right arith			"001100"
		
--PC=44
		-- divide				"001000" 
		-- to R[30] (value: 3)	"11110"
		-- in R[11] (value: 0)	"01011"
		-- the immediate 3		"0000000000000011"
